<template>
  <kennel
    :navList="navList"
    :navClass="'d-nav-bar-black'"
    :navActiveId="navActiveId"
    :isShowFooter="isShowFooter"
    :isLogin="isLogin"
    @login="handleLogin"
    @logout="handleLogout">
    <template v-slot:header-side>
      <div class="d-header-side">
        <a class="d-text-link header-logo" :href="getMicroPath('#/')">
          <img class="d-img logo-image" src="../assets/images/dog-logo-sm.png" />
          <span class="logo-text">虎啸(TigerLair)</span>
        </a>
      </div>
    </template>
    <template v-slot:layout-body>
      <router-view></router-view>
    </template>
    <template v-if="isShowFooter" v-slot:layout-footer>
      <div class="d-layout-footer">DF3S前端快速开发服务系统(DAEL开发与体验实验室)</div>
    </template>
  </kennel>
</template>

<script>
import { Kennel } from '@daelui/vdog/dist/pages'
import { mapState } from 'vuex'
import uSer from '@/service/action/user.action.js'
import ebus from '@/components/ebus'
import config from '@/micros/config'

// 判断环境是否是微应用打开
let microPath = ''
if (window.__POWERED_BY_QIANKUN__) {
  microPath = config.microPath
}

export default {
  components: {
    Kennel
  },

  computed: mapState({
    // 选中的导航id
    navActiveId: state => state.navActiveId
  }),

  data () {
    return {
      navList: [
        {
          text: '首页',
          url: ('#' + (microPath || '/')).replace('\/\/', '/'),
          id: 1
        },
        {
          text: '导航',
          url: '#' + microPath + '/nave/list',
          id: 2,
          match: '/nave',
          children: [
            {
              text: '规则管理',
              url: '#' + microPath + '/nave/rule',
              id: 21
            },
            {
              text: '环境管理',
              url: '#' + microPath + '/nave/envirment',
              id: 22
            }
          ]
        },
        {
          text: '产品',
          url: '#' + microPath + '/product/list',
          match: '/product/',
          id: 3,
          children: [
            {
              text: '页面',
              url: '#' + microPath + '/page/list',
              match: '/page/',
              id: 32
            },
            {
              text: '功能',
              url: '#' + microPath + '/page/func/list',
              match: '/page/func',
              id: 32
            }
          ]
        },
        {
          text: '编码',
          url: '#' + microPath + '/codewell/list',
          match: '/codewell',
          id: 4,
          children: [
            {
              text: '文档',
              url: '#' + microPath + '/codewell/encode/list',
              match: '/codewell',
              id: 41
            }
          ]
        },
        {
          text: '微应用',
          url: '#' + microPath + '/mapp/list',
          match: '/mapp',
          id: 20,
          children: []
        },
        {
          text: '服务',
          url: '#' + microPath + '/service/inter/list',
          match: '/service',
          id: 5,
          children: [
            {
              text: '实体',
              url: '#' + microPath + '/service/entity/list',
              id: 52
            },
            // {
            //   text: '数据库',
            //   url: '#' + microPath + '/service/database/list',
            //   id: 53
            // },
            // {
            //   text: '数据表',
            //   url: '#' + microPath + '/service/table/list',
            //   id: 54
            // },
            // {
            //   text: '组合服务',
            //   url: '#' + microPath + '/service/process/list',
            //   id: 55
            // }
          ]
        },
        {
          text: '视图',
          url: '#' + microPath + '/dview/page/list',
          match: '/dview',
          id: 6,
          children: [
            {
              text: '组件',
              url: '#' + microPath + '/dview/component/list',
              id: 62
            },
            // {
            //   text: '模板',
            //   url: '#' + microPath + '/dview/template/list',
            //   id: 64
            // },
            {
              text: '片段',
              url: '#' + microPath + '/dview/snippet/list',
              id: 65
            }
          ]
        },
        {
          text: '资源',
          url: '#' + microPath + '/resource/list',
          match: '/resource',
          id: 7,
          children: [
            {
              text: '文件',
              url: '#' + microPath + '/dfile/list',
              match: '/dfile',
              id: 72
            },
            {
              text: '目录',
              url: '#' + microPath + '/pool/list',
              match: '/pool',
              id: 73
            }
          ]
        },
        {
          text: '流程',
          url: '#' + microPath + '/process/exegroup/list',
          match: '/process/exegroup',
          id: 8,
          children: [
            {
              text: '流程线',
              url: '#' + microPath + '/process/execute/list',
              match: '/process/execute',
              id: 82
            },
            {
              text: '单元',
              url: '#' + microPath + '/process/exeunit/list',
              match: '/process/exeunit',
              id: 83
            }
          ]
        },
        {
          text: '采集',
          url: '#' + microPath + '/collect/inter/list',
          match: '/collect',
          id: 9,
          children: [
            {
              text: '接口',
              url: '#' + microPath + '/collect/inter/list',
              match: '/collect',
              id: 92
            },
            {
              text: '报错',
              url: '#' + microPath + '/collect/error/list',
              match: '/collect',
              id: 94
            },
            {
              text: '性能',
              url: '#' + microPath + '/collect/performance/list',
              match: '/collect',
              id: 96
            }
            // {
            //   text: '行为体验',
            //   url: '#' + microPath + '/collect/ube/list',
            //   id: 97
            // }
          ]
        },
        // {
        //   text: '测试',
        //   url: '#' + microPath + '/test/list',
        //   id: 9,
        //   children: [
        //     {
        //       text: '用例',
        //       url: '#' + microPath + '/test/case/list',
        //       id: 92
        //     },
        //     {
        //       text: '执行',
        //       url: '#' + microPath + '/test/execute/list',
        //       id: 93
        //     },
        //     {
        //       text: '安全',
        //       url: '#' + microPath + '/test/safe',
        //       id: 94
        //     },
        //     {
        //       text: '性能',
        //       url: '#' + microPath + '/test/performance',
        //       id: 95
        //     }
        //   ]
        // },
        {
          text: '插件',
          url: '#' + microPath + '/plugins',
          match: '/plugins',
          id: 11,
          children: [
            {
              text: '服务代理',
              url: '#' + microPath + '/proxier',
              match: '/proxier',
              id: 112
            }
          ]
        },
        // {
        //   text: '任务',
        //   url: '#' + microPath + '/task',
        //   id: 12,
        //   children: [

        //   ]
        // },
        {
          text: '文档',
          url: '#' + microPath + '/archive/list',
          match: '/archive',
          id: 14,
          children: [
            {
              text: '分类',
              url: '#' + microPath + '/archive/cat/list',
              id: 142
            },
            {
              text: '目录',
              url: '#' + microPath + '/archive/chapter/list',
              id: 143
            }
            // {
            //   text: '文件',
            //   url: '#' + microPath + '/arcfile/list',
            //   id: 143
            // }
          ]
        },
        // {
        //   text: '配置',
        //   url: '#' + microPath + '/config',
        //   id: 15,
        //   children: [
        //     {
        //       text: '环境',
        //       url: '#' + microPath + '/config/env',
        //       id: 152
        //     },
        //     {
        //       text: '参数',
        //       url: '#' + microPath + '/config/param',
        //       id: 153
        //     }
        //   ]
        // }
        {
          // text: '系统',
          // url: '#' + microPath + '/system',
          text: '字典',
          url: '#' + microPath + '/dictionary/list',
          match: ['/system', '/dictionary'],
          id: 19,
          // children: [
          //   {
          //     text: '字典',
          //     url: '#' + microPath + '/dictionary/list',
          //     match: '/system',
          //     id: 191
          //   }
          // ]
        }
      ],
      // 是否显示底部
      isShowFooter: false,
      // 是否登录
      isLogin: false
    }
  },

  mounted () {
    // 登录完成
    ebus.$off('onLoginComplete')
    ebus.$on('onLoginComplete', () => {
      this.isLogin = true
    })
    // 超时
    ebus.$off('onLoginExpire')
    ebus.$on('onLoginExpire', () => {
      this.isLogin = false
    })
    // 获取用户信息
    uSer.queryUserInfo().then(res => {
      if (res && res.data && res.data.username) {
        ebus.$emit('onLoginComplete')
      }
    })
  },

  methods: {
    handleLogin () {
      // 弹出窗口
      ebus.$emit('onShowLogin')
    },
    handleLogout () {
      uSer.logout().then(res => {

      })
      this.isLogin = false
      // 清除token
      localStorage.removeItem('daelui-token')
    }
  }
}
</script>

<style lang="less">
.d-layout-header {
  position: relative;
  z-index: 5;
}
.layout-content {
  min-height: calc(100vh - 48px - 32px - 38px - 8px - 16px);
}
.d-table-tr {
  .d-grid-actions {
    .d-text-theme {
      color: #999;
    }
  }
  &:hover {
    .d-grid-actions {
      .d-text-theme {
        color: #3391ff;
      }
    }
  }
}
.d-layout-content {
  & > .d-contenter {
    display: flex;
    width: 100%;
    min-height: 100%;
    .paner-list {
      display: flex;
      flex-direction: column;
      flex: 1;
      & > .d-paner-table {
        flex: 1;
        & > .d-paner-body {
          flex: 1;
        }
      }
    }
    & > .d-paner {
      flex: 1;
    }
  }
}
</style>
